<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>响应式原理</title>
  </head>

  <body>
    <button id="btn">Object.prototypeof删除</button>
    <script>
      let getDouble = (n) => n * 2;
      let obj = {};
      let count = 1;
      let double = getDouble(count);

      Object.defineProperty(obj, 'count', {
        get() {
          return count;
        },
        set(val) {
          count = val;
          double = getDouble(val);
        },
      });
      console.log(double); // 打印2
      obj.count = 2;
      console.log(double); // 打印4  有种自动变化的感觉

      let btn = document.querySelector('#btn');

      btn.addEventListener('click', function () {
        delete obj.count;

        console.log(double);
      });
    </script>
  </body>
</html>
